//
//  YWVerticalBtn2.m
//  YueshengToutiao
//
//  Created by jun peng on 2022/3/18.
//  Copyright © 2022 YW. All rights reserved.
//

#import "YWVerticalBtn2.h"
// 图标的比例
#define MyTabBarButtonImageRatio 40/70

@implementation YWVerticalBtn2


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }

    return self;
}

//假如是xib创建的
-(instancetype)initWithCoder:(NSCoder *)aDecoder{

    if (self = [super initWithCoder:aDecoder]) {
        
        [self setupUI];
        
    }
    return self;

}

-(void)setupUI{
    
    //图标居中
    self.imageView.contentMode = UIViewContentModeCenter;
    
    //文字居中
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    //字体大小
    self.titleLabel.font = [UIFont systemFontOfSize:13];
    
    //文字颜色
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setTitleColor:mainColor forState:UIControlStateSelected];
}


//重写取消高亮
- (void)setHighlighted:(BOOL)highlighted{}

//设置内部图片frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    
    CGFloat imageW = contentRect.size.width;
    CGFloat imageH = contentRect.size.height * MyTabBarButtonImageRatio;
    return CGRectMake(0, 0, imageW, imageH);
    
}


//设置内部文字frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    
    CGFloat titleY = contentRect.size.height * MyTabBarButtonImageRatio ;
    CGFloat titleW = contentRect.size.width;
    CGFloat titleH = contentRect.size.height - titleY;
    return CGRectMake(0, titleY, titleW, titleH);
}



@end
